﻿using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Nantianmen.Core.Services;
using Nantianmen.Core.Stores;
using Nantianmen.Shared;

namespace Nantianmen
{
    internal class AspNetClusterService : ClusterService
    {
        private CancellationToken _cancel;

        public AspNetClusterService(
            ILogger<ClusterService> logger,
            IClusterStore store,
            NantianmenErrorDescriber errorDescriber,
            IServiceProvider services) : base(logger, store, errorDescriber)
        {
            _cancel = services.GetRequiredService<IHttpContextAccessor>().HttpContext?.RequestAborted ?? CancellationToken.None;
        }

        protected override CancellationToken CancellationToken => _cancel;
    }
}
